package cc.zy.base.businesses.service.impl;


import cc.zy.base.businesses.entity.Nation;
import cc.zy.base.businesses.mapper.NationMapper;
import cc.zy.base.businesses.service.INationService;
import cc.zy.base.common.entity.QueryRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *  Service实现
 *
 * @author jiangjinlin
 * @date 2021-01-22
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class NationServiceImpl extends ServiceImpl<NationMapper, Nation> implements INationService {

    private final NationMapper nationMapper;

    @Override
    public IPage<Nation> findNations(QueryRequest request, Nation nation) {
        LambdaQueryWrapper<Nation> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<Nation> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<Nation> findNations(Nation nation) {
	    LambdaQueryWrapper<Nation> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createNation(Nation nation) {
        this.save(nation);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateNation(Nation nation) {
        this.saveOrUpdate(nation);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteNation(Nation nation) {
        LambdaQueryWrapper<Nation> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}
}
